import cn.hutool.core.util.RandomUtil;
import com.sun.jna.platform.win32.WinDef;
import scala.compat.java8.functionConverterImpls.RichIntFunctionAsFunction1;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.LongStream;

public class TTT {


    public static void main(String[] args) {
        Timer timer = new Timer();
        AtomicInteger count = new AtomicInteger(0);
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                if (1 > 2) {
                } else {
                    if (count.incrementAndGet() > 10){
                        this.cancel();
                        timer.cancel();
                    } else {
                        System.out.println("任务执行中 " + count.get());
                    }
                }
            }
        }, 0, 1000);
        System.out.println(new TTT().isValid("()"));
    }

    public String longestCommonPrefix(String[] strs) {
        Arrays.sort(strs);
        String s1 = strs[0];
        String s2 = strs[strs.length - 1];
        for (int c = 0; c < s1.length(); c++) {
            if (s2.length() > c && s2.getBytes()[c] != s1.getBytes()[c]) {
                return s1.substring(0, c);
            }
        }
        return s1;
    }

    public boolean isValid(String s) {
        char[] t = new char[s.length()];
        int i = 0;
        for (char c : s.toCharArray()) {
            if (c == ')' || c == ']' || c == '}') {
                i--;
                if (i < 0) {
                    return false;
                }
                System.out.println(t[i] + "---" + c);
                if (c - t[i] != 2 && c - t[i] != 1) {
                    return false;
                }
            } else {
                t[i] = c;
                i++;
            }
        }
        return i == 0;
    }


}
